import axios from 'axios'
// window.baseUrl = 'http://10.1.102.52:8021/apis'
window.baseUrl = 'http://123.249.101.36:8021/apis'
const service = axios.create({
  baseURL: window.baseUrl,
  timeout: 3000000,
})

// http request 拦截器
service.interceptors.request.use(
  (config) => {
    if (JSON.parse(sessionStorage.getItem('isUser'))) {
      config.headers.token = sessionStorage.getItem('token')
    }
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

const request = (options) => {
  return new Promise((resolve, reject) => {
    service(options)
    .then((response) => {
      resolve(response.data)
    })
    .catch((error) => {
      reject(error)
    })
  })
}
export default request